<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class Activity extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('activity');
        if(!$exists){
        $table = $this->table('activity', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '活动' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('imgs', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => false,'signed' => true,'comment' => '介绍图（第一张为封面）',])
            ->addColumn('name', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '名称',])
            ->addColumn('intro', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => false,'signed' => true,'comment' => '简介',])
			->addColumn('start_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => false,'signed' => true,'comment' => '开始时间',])
			->addColumn('end_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => false,'signed' => true,'comment' => '结束时间',])
            ->addColumn('lat', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '纬度',])
            ->addColumn('lng', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '经度',])
            ->addColumn('adds', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '位置',])
            ->addColumn('adds_name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '地点',])
			->addColumn('weigh', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '权重',])
			->addColumn('browse', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'default' => 1,'signed' => true,'comment' => '浏览',])
            ->addColumn('home', 'boolean', ['null' => false, 'default' => 1, 'signed' => true, 'comment' => '首页推送：0 否、1 是',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态：1 报名中、2 进行中、3 已结束、4 已下线',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
            ->create();
        }
    }
}
